package com.xzx.spark.core.acc

import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 * ${DESCRIPTION}
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2021-08-07 10:33 下午
 */
object Spark001_System {
  def main(args: Array[String]): Unit = {
    val sc = new SparkContext(new SparkConf().setMaster("local[*]").setAppName(getClass.getSimpleName))
    val rdd = sc.makeRDD(List(1, 2, 3, 4))
    val sumAccumulator = sc.longAccumulator("sum")
    rdd.foreach(x=> {
      println(Thread.currentThread().getName + Thread.currentThread().getId)
      sumAccumulator.add(x)
    })
    println(sumAccumulator.value)
    sc.stop()
  }
}
